package com.study.mike.service.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.lang.tree.Tree;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.study.mike.common.utils.MyTreeNode;
import com.study.mike.common.utils.MyTreeUtil;
import com.study.mike.mapper.ResourceMapper;
import com.study.mike.model.entity.ResourceDO;
import com.study.mike.service.ResourceService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author KangHui
 * @Date 2022/7/15 9:54
 */
@Service
public class ResourceServiceImpl extends ServiceImpl<ResourceMapper, ResourceDO> implements ResourceService {
    @Resource
    private ResourceMapper resourceMapper;

    @Override
    public List<Tree<String>> resourceList() {

        List<ResourceDO> list = resourceMapper.selectList(null);
        List<MyTreeNode<String>> nodeList = CollUtil.newArrayList();
        list.forEach(item -> {
            nodeList.add(new MyTreeNode<>(String.valueOf(item.getId()), String.valueOf(item.getParentId()), String.valueOf(item.getName()), item.getName(), null));
        });
        return MyTreeUtil.treeList(nodeList);
    }
}
